import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: a
 * Date: 2022-07-17
 * Time: 20:13
 */
public class JDBC_Update {
    public void Update(Connection connection) throws SQLException {
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入id:");
        int id=scanner.nextInt();
        System.out.println("请输入修改后的姓名:");
        String name=scanner.next();

        String sql="update student set name=? where id=?";

        PreparedStatement statement= connection.prepareStatement(sql);
        statement.setString(1,name);
        statement.setInt(2,id);

        int n=statement.executeUpdate();
        System.out.println("n="+n);

        statement.close();
        connection.close();
    }
}
